home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / Lib / SafeStart.a < prev    next >
Encoding:
Text File  |  1991-07-07  |  5.6 KB  |  154 lines  |  [TEXT/MPS ]

  1. ; file SafeStart.a
  2. ;
  3. ;
  4. ;
  5. ; This little piece of 68000 code is an header for Macintosh applications compiled under MPW,
  6. ; that does a clean job of warning the user when running on a 64K ROM machine.
  7. ; This is usefull because, under MPW 3.2 QR2, the default MPW initialisation code calls
  8. ; Get1NamedResource  blindly, without checking that the machine has at least 128K ROMs.
  9. ; If running on a Macintosh XL, Macintosh 512, or Macintosh 128,  Get1NamedResource  does not
  10. ; exist and  SetPtrSize  gets called instead. This does not always cause a bomb, but it's
  11. ; unadvisable anyway.
  12. ;
  13. ; Another reason to use this piece of code to perform the ROM version check is that many things
  14. ; like  MaxApplZone  don't work any longer under MPW 3.2 QR2; this is why Sample.c and Sample.p
  15. ; as well as MacApp sample applications bomb when compiled with MPW 3.2 QR2 and run on a
  16. ; 64K ROM machine (usually with ID=02)
  17. ;
  18. ; SafeStart's strategy is to define an alternate entry point, which overides the default one;
  19. ; the code does the necessary check, then jumps into the default entry point for C applications.
  20. ; (it's name  %__MAIN  seems hard-coded in the MPW linker)
  21. ;
  22. ; Instruction for use :
  23.  
  24. ; - for application's whose entry point is in Pascal, a little work is needed to convert to
  25. ;   the native C entry point :
  26. ;    - at the beginning of the main program file change
  27. ;           PROGRAM Whatever;
  28. ;      to 
  29. ;           UNIT Whatever;
  30. ;             INTERFACE
  31. ;               PROCEDURE MAIN; {the entry point}
  32. ;             IMPLEMENTATION
  33. ;    - before the mains program's ‘BEGIN’, add :
  34. ;               PROCEDURE MAIN;
  35. ;    - at the end of the main program, before the final ‘END.’ insert
  36. ;               END; {end of MAIN}
  37. ;    - add the option ‘-ma main=MAIN’ to the Link command line
  38. ;          
  39. ; - assemble this file  SafeStart.a  into  SafeStart.a.o , and Link with it
  40. ;   (although not currently required, it is advisable that it be the first link file)
  41. ;
  42. ; - preferably, add an ALRT ressource (ID=13579) and associated DITL, to be displayed when
  43. ;   running on old machines (if it's missing, the application will just return to Finder);
  44. ;   since the Alert is a StopAlert, leave room on the top left for the stop icon;
  45. ;   an example alert, in Rez format, is included at the end of this file.
  46. ;
  47. ; - optionaly, remove checks for 128K ROMs (search ROM85, 28E, machineType, etc…)
  48. ;   from the source code, probably saving more code than SafeStart adds.
  49. ;
  50. ;
  51. ; This is brought to you by François Grieu - RMT & Hello Informatique, France (hence the typos)
  52. ; APPLELINK : FRA0003
  53. ;
  54. ; Although this has been carefully tested (under MPW 3.2 QR2, with at least Sample.c, Sample.p,
  55. ; CPlusTESample, and MacApp 2.0.1  Calc), the author assume no reponsability for possible errors.
  56. ;
  57. ; Feel free to use, redistribute and alter in any way.
  58. ;
  59. ;
  60. ; revision history
  61. ;
  62. ;  1.01   910217   FRG   added explanations on how to use if the application is in Pascal;
  63. ;                        smoothed comments; code unchanged.
  64. ;
  65. ;  1.00   910211   FRG   first release version, for MPW 3.2 QR2
  66. ;
  67. ;————————————————————————————————————————————————————————————————————————————————————————————————
  68. ;
  69. ; assembly options
  70. ;
  71. kALRTidOld    EQU    13579    ; id of the ALRT displayed on old machines; change as needed
  72. ;————————————————————————————————————————————————————————————————————————————————————————————————
  73.         INCLUDE    'SysEqu.a'
  74.         INCLUDE    'Traps.a'
  75. ;————————————————————————————————————————————————————————————————————————————————————————————————
  76. ; this is the entry point; to avoid using too much CODE0001 space, most of the code is placed
  77. ; in the initialisation segment %A5Init, and will get unloaded with _DATAINIT (hopefully)
  78.         SEG    'Main'
  79. %_SafeEntry    MAIN    EXPORT
  80.         IMPORT    (%_SafeCheck,%__MAIN):CODE
  81.         JSR    %_SafeCheck        ; check for 64K ROMs machine
  82.         JMP    %__MAIN            ; do whatever MPW wants
  83.         ENDMAIN                ; end of main procedure %_SafeEntry
  84. ;————————————————————————————————————————————————————————————————————————————————————————————————
  85. ; this is the ‘bulk’ of the code
  86.         SEG    '%A5Init'
  87. %_SafeCheck    PROC    EXPORT
  88.  
  89.         TST.W    ROM85            ; check the kind of machine
  90.         BMI.S    OldROMs            ; -> it's a 64K ROMs machine
  91.         RTS                ; we are safe
  92. ; an old machine; first of all we must initialize the managers
  93. OldROMs        PEA     -4(A5)             ; the usual and safe place for QD globals
  94.         _InitGraf            ; don't flush events (_StopAlert will do)
  95.         _InitFonts
  96.         _InitWindows
  97.         _InitMenus
  98.         _TEInit
  99.         CLR.L    -(A7)    
  100.         _InitDialogs
  101.         _InitCursor            ; make cursor an arrow
  102. ; display the alert
  103. ; NB1: we don't care for the stack since we won't return; this saves 2 instructions
  104. ; NB2: the system is smart enough to just go on if the ALRT is not available
  105. ; NB3: since MultiFinder can't be running the default button will be outlined correctly
  106.         MOVE.W    #kALRTidOld,-(A7)
  107.         CLR.L    -(A7)
  108.         _StopAlert            ; StopAlert(kALRTidOld,nil)
  109. ; exit to Finder
  110.         _ExitToShell
  111.  
  112.         ENDPROC                ; end of procedure %_SafeCheck
  113. ;————————————————————————————————————————————————————————————————————————————————————————————————
  114.         END                ; end of file SafeStart.a
  115.  
  116.  
  117. ; asm "{active}"    # use  SafeStart.a.o  as the first link file
  118.  
  119. ; you can paste the following into your .r file to get an appropriate ALRT and DITL
  120.  
  121. resource 'ALRT' (13579, purgeable) {
  122.     {40, 36, 120, 332},
  123.     13579,
  124.     {    /* array: 4 elements */
  125.         /* [1] */
  126.         OK, visible, sound3,
  127.         /* [2] */
  128.         OK, visible, sound3,
  129.         /* [3] */
  130.         OK, visible, sound3,
  131.         /* [4] */
  132.         OK, visible, sound3
  133.     }
  134. };
  135.  
  136. resource 'DITL' (13579, purgeable) {
  137.     {    /* array DITLarray: 2 elements */
  138.         /* [1] */
  139.         {50, 170, 70, 249},
  140.         Button {
  141.             enabled,
  142.             "Cancel"
  143.         },
  144.         /* [2] */
  145.         {10, 70, 44, 289},
  146.         StaticText {
  147.             disabled,
  148.             "Sorry, but this application needs\n"
  149.             "newer ROMs to run safely."
  150.         }
  151.     }
  152. };
  153.